﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/AdminDefault.Master"
  AutoEventWireup="true" CodeBehind="ProductDetail.aspx.cs" Inherits="NguyenHoa.Web.Admin.ProductDetail" %>

<%@ Register Assembly="DevExpress.Web.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxCallback" TagPrefix="dxcb" %>
<%@ Register Assembly="DevExpress.Web.ASPxHtmlEditor.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxHtmlEditor" TagPrefix="dxhe" %>
<%@ Register Assembly="DevExpress.Web.ASPxEditors.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dxe" %>
<%@ Register Assembly="DevExpress.Web.ASPxSpellChecker.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxSpellChecker" TagPrefix="dxwsc" %>
<%@ Register Assembly="DevExpress.Web.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxTabControl" TagPrefix="dxtc" %>
<%@ Register Assembly="DevExpress.Web.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxPopupControl" TagPrefix="dxpc" %>
<%@ Register Assembly="DevExpress.Web.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxDataView" TagPrefix="dxdv" %>
<%@ Register Assembly="DevExpress.Web.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxPanel" TagPrefix="dxp" %>
<%@ Register Src="../Controls/MultiUpload.ascx" TagName="MultiUpload" TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
  <dxtc:ASPxTabControl ID="ASPxTabControl1" runat="server" ActiveTabIndex="0" TabSpacing="0px"
    Width="100%">
    <ClientSideEvents ActiveTabChanging="function(s, e) {onTabChange(s, e);}" />
    <TabStyle HorizontalAlign="Center" Width="55px">
    </TabStyle>
    <Tabs>
      <dxtc:Tab Name="ProductInfo" Text="<%$Resources:Strings, ProductInfo %>" TabStyle-Cursor="pointer">
      </dxtc:Tab>
      <dxtc:Tab Name="ProductPhoto" Text="<%$Resources:Strings, ProductPhoto %>" TabStyle-Cursor="pointer">
      </dxtc:Tab>
    </Tabs>
    <Paddings PaddingLeft="0px" />
  </dxtc:ASPxTabControl>
  <div id="frmProductInfo" style="clear: both; padding-top: 10px;">
    <table width="100%">
      <tr>
        <td>
          <asp:Label runat="server" Text="<%$ Resources:Strings, Language %>"></asp:Label>
          :
        </td>
        <td>
          <dxe:ASPxComboBox ID="cbbLanguage" runat="server" ClientInstanceName="cbbLanguage"
            ValueField="Id" TextField="Value" DataSourceID="xdsLanguage" ValueType="System.Int32">
            <ClientSideEvents ValueChanged="function(s,e){cbbLanguage_ValueChanged();}" />
          </dxe:ASPxComboBox>
        </td>
      </tr>
      <tr>
        <td>
          <asp:Label runat="server" Text="<%$ Resources:Strings, Name %>"></asp:Label>
          :
        </td>
        <td>
          <dxe:ASPxTextBox ID="txtName" ClientInstanceName="txtName" runat="server" Width="100%">
          </dxe:ASPxTextBox>
        </td>
      </tr>
      <tr>
        <td>
          <asp:Label ID="Label2" runat="server" Text="<%$ Resources:Strings, Price %>"></asp:Label>
          :
        </td>
        <td>
          <dxe:ASPxTextBox ID="txtPrice" ClientInstanceName="txtPrice" runat="server" Width="170px">
            <MaskSettings Mask="<0..999999999g>.<00..99>" />
            <ValidationSettings ErrorDisplayMode="ImageWithTooltip" Display="Dynamic" />
          </dxe:ASPxTextBox>
        </td>
      </tr>
      <tr>
        <td>
          <asp:Label runat="server" Text="<%$ Resources:Strings, Description %>"></asp:Label>
          :
        </td>
        <td>
          <dxe:ASPxMemo ID="mmSummary" ClientInstanceName="mmSummary" runat="server" Height="100px"
            Width="670px">
          </dxe:ASPxMemo>
        </td>
      </tr>
      <tr>
        <td>
          <asp:Label ID="Label1" runat="server" Text="<%$ Resources:Strings, Content %>"></asp:Label>
          :
        </td>
        <td>
          <dxhe:ASPxHtmlEditor ID="hdContent" runat="server" Width="670px" ClientInstanceName="hdContent">
            <SettingsImageUpload>
              <ValidationSettings AllowedContentTypes="image/jpeg,image/pjpeg,image/gif,image/png,image/x-png">
              </ValidationSettings>
            </SettingsImageUpload>
            <Toolbars>
              <dxhe:StandardToolbar1>
                <Items>
                  <dxhe:ToolbarCutButton>
                  </dxhe:ToolbarCutButton>
                  <dxhe:ToolbarCopyButton>
                  </dxhe:ToolbarCopyButton>
                  <dxhe:ToolbarPasteButton>
                  </dxhe:ToolbarPasteButton>
                  <dxhe:ToolbarPasteFromWordButton>
                  </dxhe:ToolbarPasteFromWordButton>
                  <dxhe:ToolbarUndoButton BeginGroup="True">
                  </dxhe:ToolbarUndoButton>
                  <dxhe:ToolbarRedoButton>
                  </dxhe:ToolbarRedoButton>
                  <dxhe:ToolbarRemoveFormatButton BeginGroup="True">
                  </dxhe:ToolbarRemoveFormatButton>
                  <dxhe:ToolbarSuperscriptButton BeginGroup="True">
                  </dxhe:ToolbarSuperscriptButton>
                  <dxhe:ToolbarSubscriptButton>
                  </dxhe:ToolbarSubscriptButton>
                  <dxhe:ToolbarInsertOrderedListButton BeginGroup="True">
                  </dxhe:ToolbarInsertOrderedListButton>
                  <dxhe:ToolbarInsertUnorderedListButton>
                  </dxhe:ToolbarInsertUnorderedListButton>
                  <dxhe:ToolbarIndentButton BeginGroup="True">
                  </dxhe:ToolbarIndentButton>
                  <dxhe:ToolbarOutdentButton>
                  </dxhe:ToolbarOutdentButton>
                  <dxhe:ToolbarInsertLinkDialogButton BeginGroup="True">
                  </dxhe:ToolbarInsertLinkDialogButton>
                  <dxhe:ToolbarUnlinkButton>
                  </dxhe:ToolbarUnlinkButton>
                  <dxhe:ToolbarInsertImageDialogButton>
                  </dxhe:ToolbarInsertImageDialogButton>
                  <dxhe:ToolbarCheckSpellingButton BeginGroup="True">
                  </dxhe:ToolbarCheckSpellingButton>
                  <dxhe:ToolbarFontColorButton>
                  </dxhe:ToolbarFontColorButton>
                  <dxhe:ToolbarBackColorButton>
                  </dxhe:ToolbarBackColorButton>
                </Items>
              </dxhe:StandardToolbar1>
              <dxhe:StandardToolbar2>
                <Items>
                  <dxhe:ToolbarParagraphFormattingEdit Width="100px">
                    <Items>
                      <dxhe:ToolbarListEditItem Text="Normal" Value="p" />
                      <dxhe:ToolbarListEditItem Text="Heading  1" Value="h1" />
                      <dxhe:ToolbarListEditItem Text="Heading  2" Value="h2" />
                      <dxhe:ToolbarListEditItem Text="Heading  3" Value="h3" />
                      <dxhe:ToolbarListEditItem Text="Heading  4" Value="h4" />
                      <dxhe:ToolbarListEditItem Text="Heading  5" Value="h5" />
                      <dxhe:ToolbarListEditItem Text="Heading  6" Value="h6" />
                      <dxhe:ToolbarListEditItem Text="Address" Value="address" />
                      <dxhe:ToolbarListEditItem Text="Normal (DIV)" Value="div" />
                    </Items>
                  </dxhe:ToolbarParagraphFormattingEdit>
                  <dxhe:ToolbarFontNameEdit>
                    <Items>
                      <dxhe:ToolbarListEditItem Text="Times New Roman" Value="Times New Roman" />
                      <dxhe:ToolbarListEditItem Text="Tahoma" Value="Tahoma" />
                      <dxhe:ToolbarListEditItem Text="Verdana" Value="Verdana" />
                      <dxhe:ToolbarListEditItem Text="Arial" Value="Arial" />
                      <dxhe:ToolbarListEditItem Text="MS Sans Serif" Value="MS Sans Serif" />
                      <dxhe:ToolbarListEditItem Text="Courier" Value="Courier" />
                    </Items>
                  </dxhe:ToolbarFontNameEdit>
                  <dxhe:ToolbarFontSizeEdit>
                    <Items>
                      <dxhe:ToolbarListEditItem Text="1 (8pt)" Value="1" />
                      <dxhe:ToolbarListEditItem Text="2 (10pt)" Value="2" />
                      <dxhe:ToolbarListEditItem Text="3 (12pt)" Value="3" />
                      <dxhe:ToolbarListEditItem Text="4 (14pt)" Value="4" />
                      <dxhe:ToolbarListEditItem Text="5 (18pt)" Value="5" />
                      <dxhe:ToolbarListEditItem Text="6 (24pt)" Value="6" />
                      <dxhe:ToolbarListEditItem Text="7 (36pt)" Value="7" />
                    </Items>
                  </dxhe:ToolbarFontSizeEdit>
                  <dxhe:ToolbarBoldButton BeginGroup="True">
                  </dxhe:ToolbarBoldButton>
                  <dxhe:ToolbarItalicButton>
                  </dxhe:ToolbarItalicButton>
                  <dxhe:ToolbarUnderlineButton>
                  </dxhe:ToolbarUnderlineButton>
                  <dxhe:ToolbarStrikethroughButton>
                  </dxhe:ToolbarStrikethroughButton>
                  <dxhe:ToolbarJustifyLeftButton BeginGroup="True">
                  </dxhe:ToolbarJustifyLeftButton>
                  <dxhe:ToolbarJustifyCenterButton>
                  </dxhe:ToolbarJustifyCenterButton>
                  <dxhe:ToolbarJustifyRightButton>
                  </dxhe:ToolbarJustifyRightButton>
                  <dxhe:ToolbarJustifyFullButton>
                  </dxhe:ToolbarJustifyFullButton>
                </Items>
              </dxhe:StandardToolbar2>
            </Toolbars>
          </dxhe:ASPxHtmlEditor>
        </td>
      </tr>
    </table>
  </div>
  <div id="frmProductPhoto" style="clear: both; padding-top: 10px; display: none;">
    <div style="float: left;">
      <dxe:ASPxCheckBox ID="ckbAll" ClientInstanceName="ckbAll" runat="server" Text="<%$Resources:Strings, SelectAllItem %>"
        Cursor="pointer">
        <ClientSideEvents CheckedChanged="function(s,e){onCheckAll();e.processOnServer=false;}" />
      </dxe:ASPxCheckBox>
    </div>
    <div style="float: right; padding-top: 5px; font-style: italic; font-size: 11px;"
      class="CommonFont">
      <asp:Label ID="lblNote" runat="server" Text="<%$Resources:Strings,ImgSizeBanner %>"></asp:Label>
    </div>
    <div style="clear: both; padding-top: 20px;">
      <dxdv:ASPxDataView ID="dvList" ClientInstanceName="dvList" runat="server" ColumnCount="5"
        OnCustomCallback="dvList_CustomCallback" OnCustomJSProperties="dvList_CustomJSProperties"
        ItemSpacing="3px" PagerPanelSpacing="0px" OnDataBound="dvList_DataBound" Width="100%"
        BackColor="#ECF6FD">
        <ItemStyle Height="122px" Width="122px" BackColor="#ECF6FD">
          <Paddings Padding="0px" />
        </ItemStyle>
        <ItemTemplate>
          <div align="center" style="width: 122px; height: 122px;">
            <img alt="" src='<%#Eval("Path") %>' width="120px" height="120px" align="middle"
              style="padding: 2px;" />
          </div>
          <div style="width: 122px; padding-top: 8px;" align="center">
            <input id="item_checkbox" type="checkbox" runat="server" style="cursor: pointer;" />
          </div>
        </ItemTemplate>
        <ContentStyle ForeColor="#CC3300">
          <Paddings PaddingLeft="10px" PaddingRight="10px" />
        </ContentStyle>
        <ClientSideEvents EndCallback="function(s,e){ondvList_EndCallback(s,e);}" BeginCallback="function(s,e){ondvList_BeginCallback(s,e);}" />
        <Paddings Padding="0px" />
        <PagerSettings Position="Bottom">
          <AllButton>
            <Image Height="18px" Width="24px" />
          </AllButton>
          <FirstPageButton>
            <Image Height="18px" Width="22px" />
          </FirstPageButton>
          <LastPageButton>
            <Image Height="18px" Width="22px" />
          </LastPageButton>
          <NextPageButton>
            <Image Height="18px" Width="20px" />
          </NextPageButton>
          <PrevPageButton>
            <Image Height="18px" Width="20px" />
          </PrevPageButton>
          <Summary Text="<%$Resources:Strings, PagerText %>" />
        </PagerSettings>
      </dxdv:ASPxDataView>
    </div>
    <div style="clear: both;">
      <dxpc:ASPxPopupControl ID="pcUpload" ClientInstanceName="pcUpload" runat="server"
        PopupHorizontalAlign="WindowCenter" PopupVerticalAlign="WindowCenter" Modal="True"
        HeaderText="<%$ Resources:Strings, Upload %>" AllowDragging="True" AllowResize="True"
        AutoUpdatePosition="True" PopupAction="None" ShowPageScrollbarWhenModal="True"
        CloseAction="CloseButton">
        <SizeGripImage Height="12px" Width="12px" />
        <ContentCollection>
          <dxpc:PopupControlContentControl>
            <dxp:ASPxPanel ID="ASPxPanel1" runat="server" Width="100%">
              <PanelCollection>
                <dxp:PanelContent>
                  <div>
                    <uc1:MultiUpload ID="MultiUpload1" runat="server" />
                  </div>
                </dxp:PanelContent>
              </PanelCollection>
            </dxp:ASPxPanel>
          </dxpc:PopupControlContentControl>
        </ContentCollection>
        <CloseButtonImage Height="18px" Width="18px" />
      </dxpc:ASPxPopupControl>
    </div>
  </div>
  <div style="float: left; padding-top: 10px; padding-left: 60px;" id="divButton">
    <div style="float: left; padding-right: 2px;">
      <dxe:ASPxButton ID="btnSave" Text="<%$ Resources:Strings, Save %>" AutoPostBack="false"
        ClientInstanceName="btnSave" runat="server">
        <ClientSideEvents Click="function(s,e){btnSave_Click();}" />
      </dxe:ASPxButton>
    </div>
    <div style="float: left; padding-right: 2px;">
      <dxe:ASPxButton ID="btnAddPhoto" ClientInstanceName="btnAddPhoto" runat="server"
        Text="<%$ Resources:Strings, Add %>" AutoPostBack="False" ClientVisible="false">
        <ClientSideEvents Click="function(s,e){pcUpload.Show();}" />
      </dxe:ASPxButton>
    </div>
    <div style="float: left; padding-right: 2px;">
      <dxe:ASPxButton ID="btnDeletePhoto" ClientInstanceName="btnDeletePhoto" runat="server"
        Text="<%$ Resources:Strings, Delete %>" AutoPostBack="False" ClientVisible="false">
        <ClientSideEvents Click="function(s,e){onDeletePhoto();}" />
      </dxe:ASPxButton>
    </div>
    <div style="float: left">
      <dxe:ASPxButton ID="btnback" Text="<%$ Resources:Strings, BackTo %>" AutoPostBack="false"
        ClientInstanceName="btnback" runat="server">
        <ClientSideEvents Click="function(){BackTo();}" />
      </dxe:ASPxButton>
    </div>
  </div>
  <asp:XmlDataSource ID="xdsLanguage" runat="server" XPath="Items/LanguageDisplay/Status">
  </asp:XmlDataSource>
  <asp:HiddenField ID="hfSelectedList" runat="server" />
  <asp:HiddenField ID="hfCheckBoxList" runat="server" />
  <asp:HiddenField ID="hfAllIdList" runat="server" />
  <asp:HiddenField ID="hfProductId" runat="server" />
  <asp:HiddenField ID="hfLocaleId" runat="server" />
  <asp:HiddenField ID="hfAlbumId" runat="server" />
  <dxcb:ASPxCallback ID="ctrlCallback" runat="server" ClientInstanceName="ctrlCallback"
    OnCallback="ctrlCallback_Callback">
    <ClientSideEvents CallbackComplete="function(s,e){ctrlCallback_CallbackComplete(s,e);}" />
  </dxcb:ASPxCallback>

  <script type="text/javascript" language="javascript">
    function ctrlCallback_CallbackComplete(s, e) {
      pcWaiting.Hide();
      if (e.result.indexOf("save") != -1) {
        SaveLocale(e.result);
        return;
      }
      
      if (e.result.indexOf("[language]") != -1) {
        LoadContent(e.result);
      }
    }
    
    function SaveLocale(rs) {
      pcWaiting.Hide();
      if (rs.indexOf("error") != -1) {
        alertMessage(rs.split('|')[1]);
      }
      else {
        if (rs.indexOf("[update]")==-1)
          document.getElementById("<%=hfLocaleId.ClientID %>").value = rs.split('|')[1];
        alertMessage('<%=(string)GetGlobalResourceObject("Messages","ERR0005") %>');
      }
    }
    
    function LoadContent(rs) {
      var values = rs.split('|');
      txtName.SetText(values[1]);
      mmSummary.SetText(values[2]);
      txtPrice.SetText(values[3]);
      hdContent.SetHtml(values[4]);
      document.getElementById("<%=hfLocaleId.ClientID %>").value = values[5];
    }
    
    function btnSave_Click() {
      pcWaiting.Show();
      ctrlCallback.SendCallback("save");
    }
    
    function BackTo() {
      window.location.href = "ProductList.aspx";
    }
    
    function cbbLanguage_ValueChanged() {
      ctrlCallback.SendCallback("language");
    }
    
    function onTabChange(s, e) {
      var tabName = e.tab.name;
      if (tabName == "ProductPhoto")
        showEditor(true);
      else
        showEditor(false);
    }
    
    function showEditor(show) {
      var frmProductInfo = document.getElementById('frmProductInfo');
      var frmProductPhoto = document.getElementById('frmProductPhoto');
      var divButton = document.getElementById('divButton');
      if (show) {
        frmProductPhoto.style.display = 'block';
        frmProductInfo.style.display = 'none';
        divButton.style.paddingLeft = '0px';
        btnSave.SetVisible(false);
        btnAddPhoto.SetVisible(true);
        btnDeletePhoto.SetVisible(true);
      }
      else {
        frmProductPhoto.style.display = 'none';
        frmProductInfo.style.display = 'block';
        divButton.style.paddingLeft = '60px';
        btnSave.SetVisible(true);
        btnAddPhoto.SetVisible(false);
        btnDeletePhoto.SetVisible(false);
        hdContent.AdjustControl();
      }
    }
    
    function ondvList_BeginCallback(s, e) {
      var ids = document.getElementById('<%=hfCheckBoxList.ClientID %>').value.split(',');
      for (var i = 0; i < ids.length; i++) {
        if (ids[i] == '')
          continue;
        var checkbox = document.getElementById(ids[i]);
        if (checkbox != null) {
          checkbox.checked = false;
        }
      }
      document.getElementById('<%=hfSelectedList.ClientID %>').value = '';
    }

    function ondvList_EndCallback(s, e) {
      document.getElementById('<%=hfSelectedList.ClientID %>').value = '';
      var error = dvList.cpInnerError;
      if (error != '') {
        if (error.indexOf('SaveOK') >= 0 || error.indexOf('DeleteOK') >= 0) {
          var para = error.split('|');
          document.getElementById('<%=hfAlbumId.ClientID %>').value = para[1];
          document.getElementById('<%=hfCheckBoxList.ClientID %>').value = para[2];
          document.getElementById('<%=hfAllIdList.ClientID %>').value = para[3];
          if (error.indexOf('SaveOK') >= 0)
            alertSuccess();
        }
        else
          alertMessage(error);
      }
      ckbAll.SetChecked(false);
    }

    function addCheckBoxId(s) {
      var id = s.id;
    }

    function onSelect(id, checked) {
      if (id == '')
        return;
      var oldSelected = document.getElementById('<%=hfSelectedList.ClientID %>').value.split(',');
      var newSelected = '';
      var isNew = true;
      for (var i = 0; i < oldSelected.length; i++) {
        if (oldSelected[i] == '')
          continue;
        if (oldSelected[i] == id) {
          isNew = false;
          if (!checked)
            continue;
        }
        newSelected += oldSelected[i] + ',';
      }
      if (isNew && checked)
        newSelected += id + ',';
      if (!checked)
        ckbAll.SetChecked(false);
      document.getElementById('<%=hfSelectedList.ClientID %>').value = newSelected;
    }

    function onDeletePhoto() {
      var deletedList = document.getElementById('<%=hfSelectedList.ClientID %>').value;
      if (confirm('<%=(string)GetGlobalResourceObject("Messages", "ERR0006") %>'))
        dvList.PerformCallback('Delete|' + deletedList);
    }

    function onCheckAll() {
      var ckbList = document.getElementById('<%=hfCheckBoxList.ClientID %>').value.split(',');
      var checked = ckbAll.GetChecked();
      for (var i = 0; i < ckbList.length; i++) {
        if (ckbList[i] == '')
          continue;
        var ckb = document.getElementById(ckbList[i]);
        if (ckb != null) {
          ckb.checked = checked;
        }
      }
      if (checked) {
        var idList = document.getElementById('<%=hfAllIdList.ClientID %>').value
        document.getElementById('<%=hfSelectedList.ClientID %>').value = idList;
      }
      else
        document.getElementById('<%=hfSelectedList.ClientID %>').value = '';
    }

    function UploadComplete() {
      pcUpload.Hide();
      dvList.PerformCallback('Save|');
    }
  </script>

</asp:Content>
